import req from "../../tool/axios"
import {MenuDir} from "../../tool/types";

//获取系统设置
const GetSystemConfig = () => {
    return req.GetForm('/admin/root/config', {}, {})
}

export interface SaveSystemConfigParams {
    token_second: number
}

//保存系统设置
const SaveSystemConfig = (data: SaveSystemConfigParams) => {
    return req.PostJson('/admin/root/config', data, {})
}

export interface GetRoleMenuItemsParams {
    id: number
}

export interface SaveRoleMenuItemsParams {
    id: number
    list: MenuDir[]
}

export interface CreateRoleParams {
    key: string
    name: string
}

const Role = {
    ReloadCASBIN: () => req.GetForm('/admin/root/role/reload', {}, {}),//重载请求鉴权
    AllList: () => req.GetForm('/admin/root/role/list', {}, {}),//获取所有的普通角色列表
    GetRoleMenuItems: (data: GetRoleMenuItemsParams) => req.GetForm('/admin/root/role/menu', data, {}),//获取指定角色的菜单权限列表，有权和无权的全部。
    SaveRoleMenuItems: (data: SaveRoleMenuItemsParams) => req.PutJson('/admin/root/role/menu', data, {}),//获取指定角色的菜单权限列表，有权和无权的全部。
    CreateRole: (data: CreateRoleParams) => req.PostJson('/admin/root/role/create', data, {}), //创建新的角色
}

const GetAllStatus = () => {
    return req.GetForm('/admin/root/status', {}, {})
}

export default {
    GetSystemConfig, SaveSystemConfig, Role, GetAllStatus
}